//
//  receiveGiftInfo.m
//  tcpoctest
//
//  Created by gump on 5/21/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveGiftInfo.h"

#import "GiftInfoDataInfo.h"

#import "GiftInfoDataSource.h"
#import "LocalPathDataSource.h"

#import "giftInfoDatabase.h"
#import "giftInfoMusicDataBase.h"

@implementation receiveGiftInfo

-(void)processreceive
{
    //返回 26char(1),8char(1),礼物ID长度char(1),
    //礼物idchar(x),礼物价格int,状态标志char(1),
    //礼物名称长度char(1),礼物名称char(x),礼物url长度char(1),
    //礼物urlchar(x),礼物所属IDchar(1)，
    //是否有音乐char(1)1有,音乐url地址长度,音乐url地址
    
    GiftInfoDataInfo *ginfo = [[GiftInfoDataInfo alloc] init];
    
    ginfo.strgiftid = [logicsb ReadUnencodeString];
    ginfo.giftprice = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
    ginfo.giftstate = [logicsb ReadChar];
    ginfo.strgiftname = [logicsb ReadUnencodeString];
    ginfo.strgifturl = [logicsb ReadUnencodeString];
    ginfo.giftBelongID = [logicsb ReadChar];
    ginfo.giftIsMusic = [logicsb ReadChar];
    
    if (ginfo.giftIsMusic == 2) {
        ginfo.giftMusicUrl = [logicsb ReadUnencodeString];
        
        [[DataControl shareControl].giftInfoDS DownLoadMusic:ginfo];
    }
    
    [[DataControl shareControl].giftInfoDS AddGIDicInfo:ginfo
                                             withGiftID:ginfo.strgiftid];
    [[DataBaseCtrol shareControl].giftInfoDB insertInfo:ginfo];
    
    if (ginfo.giftstate == GIDIS_USE) {
        [[DataControl shareControl].giftInfoDS AddToShowArr:ginfo.strgiftid];
    }
    else if(ginfo.giftstate == GIDIS_NOUSE)
    {
        [[DataControl shareControl].giftInfoDS DelShowArrByID:ginfo.strgiftid];
    }
    
    [[DataControl shareControl].UICommendDS addUICommand:UC_REFRESHCURVIEW];
    
    [self ShowLog];
}

@end
